﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SilverlightApplication1.Interfaces;

namespace SilverlightApplication1.Controls
{
    public partial class Block : AnimatedControl
    {
        public Block()
        {
            InitializeComponent();
            Loaded += Block_Loaded;
        }

        public override void RunAnimation()
        {
            var dialog = OpenDialog();
            dialog.AnimationCompleted += InvokeAnimationCompleted;
        }

        private void Block_Loaded(Object sender, RoutedEventArgs e)
        {
            this.Border.BorderThickness = new Thickness(1);
            this.Border.BorderBrush = new SolidColorBrush(Colors.Black);
            this.NameBlock.Height = this.Height;
            this.NameBlock.Width = this.Width;
        }

        private DetailsDialog OpenDialog()
        {
            DetailsDialog dialog = DetailsDialog.GetDialog();             
            dialog.DataContext = DataContext;            
            dialog.Show();
            SetBorderInactive();
            return dialog;
        }
        
        private void BlockClick(object sender, RoutedEventArgs e)
        {
            OpenDialog();
        }
        
        private void BlockActive(object sender, MouseEventArgs e)
        {
            SetBorderActive();                  
        }

        private void BlockInactive(object sender, MouseEventArgs e)
        {
            SetBorderInactive();           
        }

        private void SetBorderActive()
        {
            this.Border.BorderThickness = new Thickness(2);
            this.Border.BorderBrush = new SolidColorBrush(Colors.Red);  
        }

        private void SetBorderInactive()
        {
            this.Border.BorderThickness = new Thickness(1);
            this.Border.BorderBrush = new SolidColorBrush(Colors.Black);
        }
    }

    
}
